package com.example.sherlockzhong.plush_v2.CardIni;

import android.app.Activity;
import android.graphics.Point;
import android.view.Display;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.example.sherlockzhong.plush_v2.R;
import com.example.sherlockzhong.plush_v2.View.ScheduleHorizontalScrollFullView;
import com.example.sherlockzhong.plush_v2.View.WelcomeHorizontalScrollFullView;

import java.util.List;
import java.util.Map;

/**
 * Created by DosonLeung on 2014/8/11.
 */

public class ScheduleIni {
    /*
   * the function shape() is used to resize the  ScheduleHorizontalScrollView.
   * params:
   * LinearLayout container:the parent container of the cards
   * int cardId:the id of the card
   * int marginLeftRight:the left and right margin of the card
   * int marginTopBottom:the top and bottom margin of the card
   * return:the card instance
   * */
    private static int marginLeftRight = 20;
    private static int marginTopBottom = 20;

    public static void shapeScheduleHorizontalScrollViewFull(Activity app, ScheduleHorizontalScrollFullView v) {
        //the default scale of the subscription items
        int scheduleWidth = 480;
        int scrollDistance = 480;
        //get the width of phone screen
        Display display = app.getWindowManager().getDefaultDisplay();
        Point p = new Point();
        display.getSize(p);
        final int windowWidth = p.x;
        scheduleWidth = windowWidth;
        scrollDistance = scheduleWidth;
        v.setScrollDistance(scrollDistance);

        LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(scheduleWidth, ViewGroup.LayoutParams.MATCH_PARENT);
        LinearLayout schedule_monday = (LinearLayout) app.findViewById(R.id.schedule_monday);
        LinearLayout schedule_tuesday = (LinearLayout) app.findViewById(R.id.schedule_tuesday);
        LinearLayout schedule_wednesday = (LinearLayout) app.findViewById(R.id.schedule_wednesday);
        LinearLayout schedule_thursday = (LinearLayout) app.findViewById(R.id.schedule_thursday);
        LinearLayout schedule_friday = (LinearLayout) app.findViewById(R.id.schedule_friday);
        LinearLayout schedule_saturday = (LinearLayout) app.findViewById(R.id.schedule_saturday);
        LinearLayout schedule_sunday = (LinearLayout) app.findViewById(R.id.schedule_sunday);

        schedule_monday.setLayoutParams(params1);
        schedule_tuesday.setLayoutParams(params1);
        schedule_wednesday.setLayoutParams(params1);
        schedule_thursday.setLayoutParams(params1);
        schedule_friday.setLayoutParams(params1);
        schedule_saturday.setLayoutParams(params1);
        schedule_sunday.setLayoutParams(params1);

    }

    public static void shapeWelcomeHorizontalScrollViewFull(Activity app, WelcomeHorizontalScrollFullView v) {
        //the default scale of the subscription items
        int scheduleWidth = 480;
        int scrollDistance = 480;
        //get the width of phone screen
        Display display = app.getWindowManager().getDefaultDisplay();
        Point p = new Point();
        display.getSize(p);
        final int windowWidth = p.x;
        scheduleWidth = windowWidth;
        scrollDistance = scheduleWidth;

        //set the width and height of the layout
        WelcomeHorizontalScrollFullView.LayoutParams params = new WelcomeHorizontalScrollFullView.LayoutParams(scheduleWidth, ViewGroup.LayoutParams.MATCH_PARENT);
        params.setMargins(0, 0, 0, 0);
        //v.setLayoutParams(params);
        v.setScrollDistance(scrollDistance);

        LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(scheduleWidth, ViewGroup.LayoutParams.MATCH_PARENT);
        LinearLayout schedule_thursday = (LinearLayout) app.findViewById(R.id.welcome_thursday);
        LinearLayout schedule_friday = (LinearLayout) app.findViewById(R.id.welcome_friday);
        LinearLayout schedule_saturday = (LinearLayout) app.findViewById(R.id.welcome_saturday);
        LinearLayout schedule_sunday = (LinearLayout) app.findViewById(R.id.welcome_sunday);

        schedule_thursday.setLayoutParams(params1);
        schedule_friday.setLayoutParams(params1);
        schedule_saturday.setLayoutParams(params1);
        schedule_sunday.setLayoutParams(params1);

    }

    public static void generateList(Activity app, ListView schedulelist, List<Map<String, Object>> scheduleList) {
        String itemNames[] = {"header", "teacher", "content", "address", "week"};
        int itemIds[] = {R.id.schedule_header, R.id.schedule_teacher, R.id.schedule_content, R.id.schedule_address, R.id.schedule_week};
        SimpleAdapter sa = new SimpleAdapter(app, scheduleList, R.layout.schedule_items, itemNames, itemIds);
        schedulelist.setAdapter(sa);
    }
}
